#define _CRT_SECURE_NO_WARNINGS 1

#include <iostream>
#include <vector>
using namespace std;

class Solution
{
public:
    vector<int> sortArray(vector<int>& nums)
    {
        srand(time(nullptr));
        qsort(nums, 0, nums.size() - 1);
        return nums;
    }

    void qsort(vector<int>& nums, int l, int r)
    {
        if (l >= r)
        {
            return;
        }
        int i = l, left = l - 1, right = r + 1;
        int rand = getRandomNum(nums, l, r);
        while (i < right)
        {
            if (nums[i] < rand) swap(nums[++left], nums[i++]);
            else if (nums[i] == rand) i++;
            else swap(nums[--right], nums[i]);
        }
        qsort(nums, l, left);
        qsort(nums, right, r);
    }

    int getRandomNum(vector<int>& nums, int left, int right)
    {
        int r = rand();
        return nums[r % (right - left + 1) + left];
    }
};

int main()
{
    Solution sol;
    vector<int> nums, ret;
    nums.push_back(2);
    nums.push_back(6);
    nums.push_back(3);
    nums.push_back(8);
    nums.push_back(4);
    nums.push_back(12);
    nums.push_back(22);
    nums.push_back(23);
    nums.push_back(28);
    nums.push_back(24);
    nums.push_back(25);
    nums.push_back(26);
    nums.push_back(27);

    ret = sol.sortArray(nums);

    for (auto e : ret)
    {
        cout << e << " ";
    }

    cout << endl;
    return 0;
}